package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RxTel;
import com.ruoyi.system.mapper.RxTelMapper;
import com.ruoyi.system.service.IRxTelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 号码Controller
 *
 * @author hjf
 * @date 2025-03-03
 */
@RestController
@RequestMapping("/hmk/tel")
public class RxTelController extends BaseController {
    @Autowired
    private IRxTelService rxTelService;

    @Autowired
    private RxTelMapper rxTelMapper;

    /**
     * 查询号码列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:tel:list')")
    @GetMapping("/list")
    public TableDataInfo list(RxTel rxTel) {
        startPage();
        List<RxTel> list = rxTelService.selectRxTelList(rxTel);
        return getDataTable(list);
    }

    /**
     * 导出号码列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:tel:export')")
    @Log(title = "号码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RxTel rxTel) {
        List<RxTel> list = rxTelService.selectRxTelList(rxTel);
        ExcelUtil<RxTel> util = new ExcelUtil<RxTel>(RxTel.class);
        util.exportExcel(response, list, "号码数据");
    }

    /**
     * 获取号码详细信息
     */
    @PreAuthorize("@ss.hasPermi('hmk:tel:selectRxTelByTel')")
    @GetMapping(value = "/selectRxTelByTel/{tel}")
    public AjaxResult selectRxTelByTel(@PathVariable("tel") String tel) {
        return success(rxTelMapper.selectRxTelByTel(tel));
    }


    @PreAuthorize("@ss.hasPermi('hmk:tel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rxTelService.selectRxTelById(id));
    }


    /**
     * 新增号码
     */
    @PreAuthorize("@ss.hasPermi('hmk:tel:add')")
    @Log(title = "号码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RxTel rxTel) {
        return toAjax(rxTelService.insertRxTel(rxTel));
    }

    /**
     * 修改号码
     */
    @PreAuthorize("@ss.hasPermi('hmk:tel:edit')")
    @Log(title = "号码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RxTel rxTel) {
        return toAjax(rxTelService.updateRxTel(rxTel));
    }

    /**
     * 删除号码
     */
    @PreAuthorize("@ss.hasPermi('hmk:tel:remove')")
    @Log(title = "号码", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rxTelService.deleteRxTelByIds(ids));
    }
}
